package com.zbxx.webservice;


import com.zbxx.webservice.api.HelloService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;


/**
 * @author
 * @date 2019/06/10
 */
public class WebServiceRestful{

    public static void main(String[] args) throws Exception {
        //代理方式
        // soap 不支持 get请求
        String weatherUrl = "http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl";
        String url = "http://localhost:8888/webservice/hello?wsdl";
      /*  JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client= clientFactory.createClient(url);
        Object[] result = client.invoke("getDomesticCity");
        System.out.println(result[0]);*/
        //undefined element declaration 's:schema'
        //java解析不了 这个标签

        //静态代理
       /* JaxWsProxyFactoryBean proxyFactoryBean = new JaxWsProxyFactoryBean();
        proxyFactoryBean.setAddress("http://localhost:8888/webservice/hello");
        HelloService helloService = proxyFactoryBean.create(HelloService.class);
        System.out.println(helloService.hello("aaa","aa"));
        */

        JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client= clientFactory.createClient(url);
        Object result = client.invoke("hello","aaa","bbbb")[0];
        //这里需要 实现类 和服务类 namespace 一致  要么同一个包 要么修改namespace
        System.out.println(result);

        //请求restful
       /* Response response = WebClient.create(url).accept(MediaType.APPLICATION_ATOM_XML_TYPE,
                MediaType.TEXT_XML_TYPE).post(null);
        System.out.println(response.readEntity(String.class));*/
    }
    }


